//
//  ProductDetailViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/20.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "ZZLayout.h"
#import "LSTPopView.h"
#import "GKPhotoBrowser.h"
#import <SDImageCache.h>

#import "ProductDetailModel.h"
#import "CommonShopCartModel.h"

#import "ProductSKUView.h"
#import "TT_MediaBannerView.h"
#import "StoreDetailNoticeView.h"
#import "ProductDetailNaviView.h"
#import "ProductDetailBottomView.h"
#import "ProductDetailEvaluationHeader.h"
#import "ProductDetailNormalSectionView.h"
#import "ProductDetailSectionFooterView.h"

#import "DetailTextCell.h"
#import "ProductDetailRichTextCell.h"
#import "MarriageProductCell.h"
#import "ProductDetailInfoCell.h"
#import "ProductDetailCouponCell.h"
#import "ProductDetailEvaluationCell.h"
#import "ProductDetailNormalShowCell.h"

#import "ShopCartViewController.h"
#import "SubmitOrderViewController.h"
#import "CouponCollectPopViewController.h"
#import "MessageCenterViewController.h"
#import "TT_ConversationDetailViewController.h"
#import "EvaluationDetailViewController.h"
#import "EvaluateListViewController.h"
#import "ProductDetailViewController.h"

@interface ProductDetailViewController ()
<UICollectionViewDelegate,
UICollectionViewDataSource,
ZZLayoutDelegate,
SDCycleScrollViewDelegate,
GKPhotoBrowserDelegate,
ProductDetailRichTextCellDelegate>

@property (nonatomic, strong) UICollectionView *collectionView;

@property (nonatomic, strong) TT_MediaBannerView *mediaBanner;

@property (nonatomic, strong) ProductDetailNaviView *naviView;

@property (nonatomic, strong) ProductDetailBottomView *bottomView;


@property (nonatomic, strong) LSTPopView *popView;
@property (nonatomic, strong) ProductSKUView *skuView;
@property (nonatomic, strong) StoreDetailNoticeView *noticeView;

@property (nonatomic, strong) ProductDetailModel *productDetailmodel;

//@property (nonatomic, strong) CommonSkuModel *selectModel;

@property (nonatomic, strong) CommonShopCartModel *handleModel;

@property (nonatomic, assign) NSTimeInterval lastTime;

@end

@implementation ProductDetailViewController

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];

    if (self.mediaBanner) {
        [self.mediaBanner.avPlayer pause];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessAction) name:@"BA_LoginSuccess" object:nil];
    
    [self request_goodsDetail];
}

- (void)loginSuccessAction {
    [self.collectionView reloadData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleStep) name:UIApplicationDidEnterBackgroundNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleStep) name:UIApplicationWillTerminateNotification object:nil];
    
    self.lastTime = [Utilities getCurrentServerTimestamp];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil];
    
    if (self.mediaBanner) {
        [self.mediaBanner.avPlayer pause];
    }
    
    [self handleStep];
}

- (void)appBecomeActive {
    self.lastTime = [Utilities getCurrentServerTimestamp];
}

- (void)handleStep {

    [[BA_BusinessHelper shared] addFootPrintWith:self.goodsId lastTime:self.lastTime And:self.productDetailmodel.sellerModel.sellerId type:BusinessCollectType_goods];
}

- (void)prepareData {
    ProductDetailModel *detailModel = self.productDetailmodel;
    //组合数据
    CommentRichTextModel *richTextModel = [[CommentRichTextModel alloc]init];
    richTextModel.richContent = detailModel.sellerGoodsModel.goodsDetailText;
    richTextModel.images = detailModel.imgTextList;
    detailModel.richTextModel = richTextModel;
    //组合数据
    //richContentAttriteStr、richTextFrame
    NSMutableAttributedString *titleAttributes = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",richTextModel.richContent]];
    titleAttributes.font = kFontRegular14;
    titleAttributes.color = kColor51;
    titleAttributes.lineSpacing = 5*ADAPTER_WIDTH;
    richTextModel.richContentAttriteStr = titleAttributes;
    richTextModel.richTextFrame = CGRectMake(10*ADAPTER_WIDTH, 10*ADAPTER_WIDTH, WIDTH - 20*ADAPTER_WIDTH, [YYTextLayout layoutWithContainerSize:CGSizeMake(WIDTH - 20*ADAPTER_WIDTH, MAXFLOAT) text:titleAttributes].textBoundingSize.height);
    
    //richImageModulesTop
    richTextModel.richImageModulesTop = richTextModel.richContent.length == 0 ? 10*ADAPTER_WIDTH : CGRectGetMaxY(richTextModel.richTextFrame) + 20*ADAPTER_WIDTH;
    //预先加载
    CGFloat cacheNumber = 0;
    CGFloat shouldLoadingNumber = 0;
    SDImageCache *cache = [SDImageCache sharedImageCache];
    CGFloat orinY = richTextModel.richImageModulesTop;
    for (NSInteger index = 0; index < richTextModel.images.count; index ++) {
        CommonMediaModel *mediaModel = richTextModel.images[index];
        UIImage *orinImage = [cache imageFromDiskCacheForKey:mediaModel.url];
        if ([cache diskImageDataExistsWithKey:mediaModel.url] && orinImage) {
            cacheNumber = cacheNumber + 1;
            mediaModel.itemHeight = WIDTH * orinImage.size.height / orinImage.size.width;
            orinY = orinY + mediaModel.itemHeight;
        } else {
            shouldLoadingNumber = shouldLoadingNumber + 1;
            mediaModel.itemHeight = 300*ADAPTER_WIDTH;
        }
    }
    if (richTextModel.images.count == 0) {
        richTextModel.richTextModulesHeight = orinY;
        richTextModel.allImagesCache = NO;
    } else {
        if (cacheNumber == richTextModel.images.count) {
            richTextModel.richTextModulesHeight = orinY;
            richTextModel.allImagesCache = YES;
        } else {
            CGFloat orinY = richTextModel.richImageModulesTop;
            orinY = orinY + richTextModel.images.count * richTextModel.images.firstObject.itemHeight;
            richTextModel.richTextModulesHeight = orinY;
            richTextModel.allImagesCache = NO;
            //预先加载把
            for (NSInteger index = 0; index < richTextModel.images.count; index ++) {
                NSString *url = richTextModel.images[index].url;
                [[[UIImageView alloc]init]sd_setImageWithURL:url.wppURL completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                    
                }];
            }
        }
    }
}



- (void)initView {
    
    self.navigationController.navigationBarHidden = YES;
    #if RT_INTERACTIVE_PUSH
        self.rt_navigationController.rt_enableInteractivePush = YES;
    #endif
    
    [self refreshNaviStatus];
    [self initMediaBanner];
    [self.collectionView addSubview:self.mediaBanner];
    self.collectionView.contentInset = UIEdgeInsetsMake(TTScreenWidth, 0, 0, 0);
    
    [self.view addSubview:self.collectionView];
    [self.view addSubview:self.naviView];
    [self.view addSubview:self.bottomView];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(60 + Bottom_SafeHeight);
    }];
    
    [self.naviView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(kStatusBarHeight + NavBar_Height);
    }];
    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(self.bottomView.mas_top).offset(-1);
    }];
    
    [self initViewAction];
    
    [RACObserve([TT_MessageManager manager], totalUnReadCount) subscribeNext:^(id x) {
        if ([TT_MessageManager manager].totalUnReadCount > 0) {
            self.naviView.msgBtn.badgeValue = [NSString stringWithFormat:@"%d",[TT_MessageManager manager].totalUnReadCount];
            self.naviView.msgBtn.badgeBGColor = [UIColor redColor];
        } else {
            self.naviView.msgBtn.badgeValue = @"";
            self.naviView.msgBtn.badgeBGColor = [UIColor clearColor];
        }
    }];
}

- (void)initViewAction {
    
    WEAKSELF
    
    self.naviView.ProductDetailNaviViewBlock = ^(ProductDetailNaviActionType actionType) {
        switch (actionType) {
            case ProductDetailNaviActionType_back:{
                [weakSelf goBack];
            } break;
            case ProductDetailNaviActionType_collect:{
                [[BA_BusinessHelper shared] callCollectStoreWith:weakSelf.goodsId
                                                   currentStatus:weakSelf.productDetailmodel.isCollect
                                                            type:BusinessCollectType_goods
                                                        comption:^(BOOL success) {
                    weakSelf.productDetailmodel.isCollect = !weakSelf.productDetailmodel.isCollect;
                    [weakSelf refreshNaviStatus];
                }];

            } break;
            case ProductDetailNaviActionType_share:{

                [weakSelf openLoginWithCompletion:^(BOOL isLogin, NSDictionary * _Nonnull options) {
                    if (isLogin) {
                        [weakSelf share];
                    }
                }];

            } break;
            case ProductDetailNaviActionType_im:{

                MessageCenterViewController *vc = [[MessageCenterViewController alloc] init];
                [weakSelf.navigationController pushViewController:vc animated:YES];
                
            } break;
            default:
                break;
        }
    };
    
    self.skuView.ProductSKUViewBlock = ^(CommonSkuModel * _Nonnull model, ProductSKUViewActionType type) {
      
        //像购物车模型一样在这里塞数据
        weakSelf.handleModel.sellerGoodsSpecs = model;
        weakSelf.handleModel.goodsId = weakSelf.goodsId;
        weakSelf.handleModel.sellerId = weakSelf.productDetailmodel.sellerModel.sellerId;
        weakSelf.handleModel.sgsId = model.sgsId;
        weakSelf.handleModel.goodsNum = model.goodsNum;
        
        [weakSelf.popView dismiss];
        [weakSelf.collectionView reloadData];

        switch (type) {
            case ProductSKUViewActionType_cart:{//加购物车
                
                [weakSelf request_AddCart];
            } break;
            case ProductSKUViewActionType_buy:{//去购买
                
                //如果是新人免单商品&&购买数量大于1
                if (self.productDetailmodel.sellerGoodsModel.isNewId.length > 0 && model.goodsNum > 1) {
                    [SVProgressHUD showErrorWithStatus:@"新人免单商品仅支持单独购买"];
                    [SVProgressHUD dismissWithDelay:1];
                    
                } else {
                    [weakSelf goSubmitOrder];
                }
                
            } break;
            default:
                break;
        }
        
    };
    
    self.bottomView.ProductDetailBottomViewBlock = ^(ProductDetailBottomActionType actionType) {
      
        switch (actionType) {
            case ProductDetailBottomActionType_im:{

                [[TT_IMContactManager manager] ImContactWithStoreId:weakSelf.productDetailmodel.sellerModel.sellerId];
                
            } break;
            case ProductDetailBottomActionType_goCart:{
                
                ShopCartViewController *vc = [[ShopCartViewController alloc] init];
                vc.storeId = weakSelf.productDetailmodel.sellerModel.sellerId;
                [weakSelf.navigationController pushViewController:vc animated:YES];
                
            } break;
            case ProductDetailBottomActionType_addCart:{
                
                if (weakSelf.handleModel.sellerGoodsSpecs.sgsId) {
                    [weakSelf request_AddCart];
                } else {
                    [weakSelf showSKUWithType:ProductSKUViewActionType_cart];
                }
                
            } break;
            case ProductDetailBottomActionType_buy:{
                
                if (weakSelf.handleModel.sellerGoodsSpecs.sgsId) {
                    
                    //如果是新人免单商品&&购买数量大于1
                    if (self.productDetailmodel.sellerGoodsModel.isNewId.length > 0 && weakSelf.handleModel.sellerGoodsSpecs.goodsNum > 1) {
                        [SVProgressHUD showErrorWithStatus:@"新人免单商品不支持多个一起下单"];
                        [SVProgressHUD dismissWithDelay:1];
                        
                    } else {
                        [weakSelf goSubmitOrder];
                    }
                    
                } else {
                    [weakSelf showSKUWithType:ProductSKUViewActionType_buy];
                }

            } break;
            default:
                break;
        }
    };
}

- (void)goSubmitOrder {
        
    if ([TTUserModel sharedObject].token.length > 0) {
        NSMutableArray <CommonShopCartModel *>*array = @[].mutableCopy;
        self.handleModel.sellerGoodsModel = self.productDetailmodel.sellerGoodsModel;
        self.handleModel.sellerModel = self.productDetailmodel.sellerModel;
        self.handleModel.sellerId =  self.productDetailmodel.sellerModel.sellerId;
        
        [array addObject:self.handleModel];
        SubmitOrderViewController *vc = [[SubmitOrderViewController alloc]init];
        vc.dataArray = array.mutableCopy;
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        
        [self openLoginWithCompletion:^(BOOL isLogin, NSDictionary * _Nonnull options) {}];
    }
}

- (void)initMediaBanner {
        
        self.mediaBanner = [[TT_MediaBannerView alloc] initWithType:self.productDetailmodel.videoUrl.length>0?YES:NO];
        self.mediaBanner.frame = CGRectMake(0, -TTScreenWidth, TTScreenWidth, TTScreenWidth);
    //    self.mediaBanner.delegate = self;
        self.mediaBanner.bannerView.delegate = self;
        self.mediaBanner.backgroundColor = UIColorHex(0xf1f1f1);
        self.mediaBanner.showsVerticalScrollIndicator = NO;
        self.mediaBanner.showsHorizontalScrollIndicator = NO;
        self.mediaBanner.pagingEnabled = YES;
        self.mediaBanner.bounces = NO;
        
        //这里后期优化   根据是否有视频来加载   根据视频数量加载等等  都可以
        if (self.productDetailmodel.videoUrl.length > 0) {    //有视频地址的时候
            self.mediaBanner.isShowVideoView = YES;
            [self.mediaBanner.avPlayer initPlayerWithUrlString:self.productDetailmodel.videoUrl AndMaskUrl:self.productDetailmodel.bannerPics.firstObject];

            self.mediaBanner.contentSize = CGSizeMake(2 * TTScreenWidth, 0);

        } else {  //无视频地址的时候
            self.mediaBanner.isShowVideoView = NO;
            self.mediaBanner.contentSize = CGSizeMake(TTScreenWidth, 0);
            self.mediaBanner.bannerView.infiniteLoop = YES;
        }

        self.mediaBanner.currentindex = 0;
        self.mediaBanner.bannerView.imageURLStringsGroup = self.productDetailmodel.bannerPics;
        self.mediaBanner.pageLabel.text =  [NSString stringWithFormat:@"1/%ld",self.productDetailmodel.bannerPics.count];
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    
    if (self.productDetailmodel.bannerPics.count > 0) {
        [self showImageWithArray:self.productDetailmodel.bannerPics index:index];
    }
}

- (void)showImageWithArray:(NSArray *)imageUrls index:(NSInteger)index {
    NSMutableArray *photos = [NSMutableArray new];
    
    [imageUrls enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        GKPhoto *photo = [GKPhoto new];
        photo.url = [NSURL URLWithString:obj];
        [photos addObject:photo];
    }];
    
    GKPhotoBrowser *browser = [GKPhotoBrowser photoBrowserWithPhotos:photos currentIndex:index];
    browser.showStyle = GKPhotoBrowserShowStyleNone;
    browser.hideStyle = GKPhotoBrowserHideStyleZoomScale;
    
    browser.delegate  = self;
    [browser showFromVC:self];
}

- (void)goBack {
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark- 协议方法
//collectionView的协议方法
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 5;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    switch (section) {
        case ProductDetailSectionType_productInfo:{
            return 7;
        } break;
        case ProductDetailSectionType_productEvaluationTag:{
            return 0;
        } break;
        case ProductDetailSectionType_productEvaluation:{
            return 0;
        } break;
        case ProductDetailSectionType_productGraphicDetail:{
            return 1;
        } break;
        case ProductDetailSectionType_productRecommend:{
            return self.productDetailmodel.sellerGoodsList.count;
        } break;
        default:
            break;
    }
    return 0;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    
//    ProductDetailEvaluationHeader
    
    if (kind == UICollectionElementKindSectionHeader) {
        
        switch (indexPath.section) {
            case ProductDetailSectionType_productInfo:{

                ProductDetailNormalSectionView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailNormalSectionView" forIndexPath:indexPath];
                headerView.sectionTitle.text = @"";
                headerView.sectionSubTitle.text = @"";
                return headerView;
                
            } break;
            case ProductDetailSectionType_productEvaluationTag:{

                ProductDetailNormalSectionView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailNormalSectionView" forIndexPath:indexPath];
                headerView.sectionTitle.text = @"用户评价";
                headerView.sectionSubTitle.text = @"查看全部";
                
                WEAKSELF
                [headerView addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
                   
                    EvaluateListViewController *vc = [[EvaluateListViewController alloc] init];
                    vc.goodsId = weakSelf.goodsId;
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                }];
                return headerView;
                
            } break;
            case ProductDetailSectionType_productEvaluation:{

                ProductDetailEvaluationHeader *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailEvaluationHeader" forIndexPath:indexPath];
                
                if (self.productDetailmodel.evaluateArray.count > 0) {
                    [headerView fillHeadWithModel:self.productDetailmodel.evaluateArray.firstObject];
                }
                
                WEAKSELF
                [headerView addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
                   
                    EvaluationDetailViewController *vc = [[EvaluationDetailViewController alloc] init];
                    vc.ueId = self.productDetailmodel.evaluateArray.firstObject.ueId;
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                }];

                return headerView;
                
            } break;
            case ProductDetailSectionType_productGraphicDetail:{

                ProductDetailNormalSectionView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailNormalSectionView" forIndexPath:indexPath];
                headerView.sectionTitle.text = @"图文详情";
                headerView.sectionSubTitle.text = @"";
                return headerView;
                
            } break;
            case ProductDetailSectionType_productRecommend:{

                ProductDetailNormalSectionView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailNormalSectionView" forIndexPath:indexPath];
                headerView.sectionTitle.text = @"为你推荐";
                headerView.sectionSubTitle.text = @"";
                return headerView;
                
            } break;
            default: {
                
                ProductDetailNormalSectionView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailNormalSectionView" forIndexPath:indexPath];
                return headerView;
            } break;
        }

    } else {
        ProductDetailSectionFooterView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ProductDetailSectionFooterView" forIndexPath:indexPath];

        return footerView;
    }
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    WEAKSELF
    switch (indexPath.section) {
        case ProductDetailSectionType_productInfo:{
            switch (indexPath.row) {
                case ProductInfoCellType_banner:{
                } break;
                case ProductInfoCellType_info:{
                } break;
                case ProductInfoCellType_coupon:{
                    CouponCollectPopViewController *pop = [[CouponCollectPopViewController alloc]initDefaultHeight:0.6*TTScreenHeight vc:self dataSource:self.productDetailmodel.couponArray];
                    STPopupController *popVericodeController = [[STPopupController alloc] initWithRootViewController:pop];
                    popVericodeController.style = STPopupStyleBottomSheet;
                    [popVericodeController presentInViewController:self];
                    pop.selectIndex = ^(NSInteger index) {
                        
                        [[BA_BusinessHelper shared] callgetCouponWith:weakSelf.productDetailmodel.couponArray[index].scoId And:weakSelf.productDetailmodel.sellerModel.sellerId comption:^(BOOL success) {
                            
                            if (success) {

                                [SVProgressHUD showSuccessWithStatus:@"领取成功"];
                                [SVProgressHUD dismissWithDelay:1];
                            }
                        }];
                    };

                } break;
                case ProductInfoCellType_freight:{
                } break;
                case ProductInfoCellType_sku:{

                    [self showSKUWithType:ProductSKUViewActionType_none];
                } break;
                case ProductInfoCellType_service:{
                    self.noticeView.itemTitle = @"服务内容";
                    NSString *promise =  [self.productDetailmodel.promiseArray componentsJoinedByString:@" "];
                    self.noticeView.itemContent = promise;
                    [self showNotice];
                } break;
                case ProductInfoCellType_logistics:{
                } break;
                    
                default:
                    break;
            }
                        
        } break;
        case ProductDetailSectionType_productEvaluationTag:{

        } break;
        case ProductDetailSectionType_productEvaluation:{

        } break;
        case ProductDetailSectionType_productGraphicDetail:{

        } break;
        case ProductDetailSectionType_productRecommend:{

            ProductDetailViewController *vc = [[ProductDetailViewController alloc] init];
            vc.goodsId = self.productDetailmodel.sellerGoodsList[indexPath.row].goodsId;
            [self.navigationController pushViewController:vc animated:YES];
            
        } break;
        default:
            break;
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    WEAKSELF
    switch (indexPath.section) {
        case ProductDetailSectionType_productInfo:{

            switch (indexPath.row) {
                case ProductInfoCellType_banner:{
                    
                    ProductDetailNormalShowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductDetailNormalShowCellID" forIndexPath:indexPath];
                    return cell;
                    
                } break;
                case ProductInfoCellType_info:{
                    
                    ProductDetailInfoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductDetailInfoCellID" forIndexPath:indexPath];
                    [cell fillCellWithModel:self.productDetailmodel.sellerGoodsModel];
                    
                    cell.ProductDetailInfoLoginBlock = ^{
                        
                        [weakSelf openLoginWithCompletion:^(BOOL isLogin, NSDictionary * _Nonnull options) {
                            if (isLogin) {
                                [weakSelf.collectionView reloadData];
                            }
                        }];
                    };
                    
                    return cell;
                    
                } break;
                case ProductInfoCellType_coupon:{
                    
                    ProductDetailCouponCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductDetailCouponCellID" forIndexPath:indexPath];
                    cell.dataArray = self.productDetailmodel.couponArray;
                    return cell;
                    
                } break;
                case ProductInfoCellType_freight:{
                    ProductDetailNormalShowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductDetailNormalShowCellID" forIndexPath:indexPath];
                    cell.mainTitleLab.text = @"运费";
                    CommonExpressModel *model = self.productDetailmodel.sellerExpress;
                    
                    if (model.seFreight > 0) {
                        cell.subTitleLab.text =[NSString stringWithFormat:@"运费：¥%@，满¥%@包邮",[Utilities changeDoubleToString:model.seFreight],[Utilities changeDoubleToString:model.seFreeFreight]];
                    } else {
                        cell.subTitleLab.text =@"免运费";
                    }
                    cell.actionArrow.hidden = YES;
                    return cell;
                    
                } break;
                case ProductInfoCellType_sku:{
                    
                    ProductDetailNormalShowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductDetailNormalShowCellID" forIndexPath:indexPath];
                    cell.mainTitleLab.text = @"规格";
                    
                    if (weakSelf.handleModel.sellerGoodsSpecs.sgsId) {
                        cell.subTitleLab.text = [NSString stringWithFormat:@"已选‘%@’",self.handleModel.sellerGoodsSpecs.specName];
                    } else {
                        cell.subTitleLab.text = @"选择规格";
                    }
                    cell.actionArrow.hidden = NO;
                    
                    return cell;
                    
                } break;
                case ProductInfoCellType_service:{
                    
                    ProductDetailNormalShowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductDetailNormalShowCellID" forIndexPath:indexPath];
                    cell.mainTitleLab.text = @"服务";
                    
                    NSString *promise =  [self.productDetailmodel.promiseArray componentsJoinedByString:@" "];
                    cell.subTitleLab.text = promise;
                    
                    cell.actionArrow.hidden = NO;
                    return cell;
                    
                } break;
                case ProductInfoCellType_logistics:{
                    
                    ProductDetailNormalShowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductDetailNormalShowCellID" forIndexPath:indexPath];
                    cell.mainTitleLab.text = @"发货地";
                    cell.subTitleLab.text = self.productDetailmodel.sellerModel.sellerAddress;
                    cell.actionArrow.hidden = YES;
                    
                    return cell;
                    
                } break;
                    
                default:
                    break;
            }
            
        } break;
        case ProductDetailSectionType_productEvaluationTag:{

        } break;
        case ProductDetailSectionType_productEvaluation:{
            
            ProductDetailEvaluationCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductDetailEvaluationCellID" forIndexPath:indexPath];
            
            if (self.productDetailmodel.evaluateArray.count > 0) {
                [cell fillCellWithModel:self.productDetailmodel.evaluateArray.firstObject];
            }
            
            return cell;

        } break;
        case ProductDetailSectionType_productGraphicDetail:{
            
            ProductDetailRichTextCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductDetailRichTextCellID" forIndexPath:indexPath];
            cell.delegate = self;
            cell.richTextModel = self.productDetailmodel.richTextModel;
            cell.parentVC = self;
            return cell;

        } break;
        case ProductDetailSectionType_productRecommend:{

            MarriageProductCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MarriageProductCellID" forIndexPath:indexPath];
            [cell fillCellWithModel:self.productDetailmodel.sellerGoodsList[indexPath.row]];
            return cell;
            
        } break;
        default:
            break;
    }
    
    ProductDetailNormalShowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProductDetailNormalShowCellID" forIndexPath:indexPath];
    return cell;
}

//ZZLyout的流协议方法
- (CGFloat)layout:(ZZLayout *)layout heightForRowAtIndexPath:(NSIndexPath *)indexPath {//返回item的高
    switch (indexPath.section) {
        case ProductDetailSectionType_productInfo:{

            switch (indexPath.row) {
                case ProductInfoCellType_banner:{
                    return CGFLOAT_MIN;
                } break;
                case ProductInfoCellType_info:{
                    return 110;
                } break;
                case ProductInfoCellType_coupon:{
                    
                    if (self.productDetailmodel.couponArray.count == 0) {
                        return CGFLOAT_MIN;
                    } else {
                        return 50;
                    }
                } break;
                case ProductInfoCellType_freight:{
                    return 50;
                } break;
                case ProductInfoCellType_sku:{
                    return 50;
                } break;
                case ProductInfoCellType_service:{
                    return 50;
                } break;
                case ProductInfoCellType_logistics:{
                    return 50;
                } break;
                default:
                    break;
            }
            
        } break;
        case ProductDetailSectionType_productEvaluationTag:{
            return CGFLOAT_MIN;
        } break;
        case ProductDetailSectionType_productEvaluation:{
            
            if (self.productDetailmodel.evaluateArray.count > 0) {
                return [ProductDetailEvaluationCell calculateHeightWithModel:self.productDetailmodel.evaluateArray.firstObject];
            }
            return CGFLOAT_MIN;

        } break;
        case ProductDetailSectionType_productGraphicDetail:{
            
            return _productDetailmodel.richTextModel.richTextModulesHeight;

        } break;
        case ProductDetailSectionType_productRecommend:{
            
            if (self.productDetailmodel.sellerGoodsList.count > 0) {
                return [MarriageProductCell calculateHeightWithWidth:TTScreenWidth];
            } else {
                return CGFLOAT_MIN;
            }
        } break;
        default:
            break;
    }

    return CGFLOAT_MIN;
}

- (NSInteger)layout:(ZZLayout *)layout columnNumberAtSection:(NSInteger)section {//每个区有几列
    
    switch (section) {
        case ProductDetailSectionType_productInfo:{
            return 1;
        } break;
        case ProductDetailSectionType_productEvaluationTag:{
            return 1;
        } break;
        case ProductDetailSectionType_productEvaluation:{
            return 1;
        } break;
        case ProductDetailSectionType_productGraphicDetail:{
            return 1;
        } break;
        case ProductDetailSectionType_productRecommend:{
            return 2;
        } break;
        default:
            break;
    }
    return 0;
}

- (UIEdgeInsets)layout:(ZZLayout *)layout insetForSectionAtIndex:(NSInteger)section {//设置每个区的边距
    
    switch (section) {
        case ProductDetailSectionType_productInfo:{
            return UIEdgeInsetsMake(0, 0, 0, 0);
        } break;
        case ProductDetailSectionType_productEvaluationTag:{
            return UIEdgeInsetsMake(0, 0, 0, 0);
        } break;
        case ProductDetailSectionType_productEvaluation:{
            return UIEdgeInsetsMake(0, 0, 0, 0);
        } break;
        case ProductDetailSectionType_productGraphicDetail:{
            return UIEdgeInsetsMake(0, 0, 0, 0);
        } break;
        case ProductDetailSectionType_productRecommend:{
            if (self.productDetailmodel.sellerGoodsList.count > 0) {
                return UIEdgeInsetsMake(15, 15, 15, 15);
            } else {
                return UIEdgeInsetsMake(0, 0, 0, 0);
            }
        } break;
        default:
            break;
    }
    
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

- (NSInteger)layout:(ZZLayout *)layout lineSpacingForSectionAtIndex:(NSInteger)section {//设置每个区的行间距
    switch (section) {
        case ProductDetailSectionType_productInfo:{
            return 0;
        } break;
        case ProductDetailSectionType_productEvaluationTag:{
            return 0;
        } break;
        case ProductDetailSectionType_productEvaluation:{
            return 0;
        } break;
        case ProductDetailSectionType_productGraphicDetail:{
            return 0;
        } break;
        case ProductDetailSectionType_productRecommend:{
            if (self.productDetailmodel.sellerGoodsList.count > 0) {
                return 10;
            } else {
                return 0;
            }
        } break;
        default:
            break;
    }
    return 0;
}

- (CGFloat)layout:(ZZLayout*)layout interitemSpacingForSectionAtIndex:(NSInteger)section {//设置每个区的列间距
    switch (section) {
        case ProductDetailSectionType_productInfo:{
            return 0;
        } break;
        case ProductDetailSectionType_productEvaluationTag:{
            return 0;
        } break;
        case ProductDetailSectionType_productEvaluation:{
            return 0;
        } break;
        case ProductDetailSectionType_productGraphicDetail:{
            return 0;
        } break;
        case ProductDetailSectionType_productRecommend:{
            if (self.productDetailmodel.sellerGoodsList.count > 0) {
                return 10;
            } else {
                return 0;
            }
        } break;
        default:
            break;
    }
    return 0;
}

- (CGSize)layout:(ZZLayout *)layout referenceSizeForHeaderInSection:(NSInteger)section {//设置区头的高度
    switch (section) {
        case ProductDetailSectionType_productInfo:{
            return CGSizeMake(TTScreenWidth, CGFLOAT_MIN);
        } break;
        case ProductDetailSectionType_productEvaluationTag:{
            if (self.productDetailmodel.evaluateArray.count > 0) {
                return CGSizeMake(TTScreenWidth, 50);
            }
            return CGSizeMake(TTScreenWidth, CGFLOAT_MIN);
        } break;
        case ProductDetailSectionType_productEvaluation:{
            
            if (self.productDetailmodel.evaluateArray.count > 0) {
                return CGSizeMake(TTScreenWidth, self.productDetailmodel.evaluateArray.firstObject.itemHeight);
            }
            return CGSizeMake(TTScreenWidth, CGFLOAT_MIN);

        } break;
        case ProductDetailSectionType_productGraphicDetail:{
            return CGSizeMake(TTScreenWidth, 50);
        } break;
        case ProductDetailSectionType_productRecommend:{
            if (self.productDetailmodel.sellerGoodsList.count > 0) {
                return CGSizeMake(TTScreenWidth, 50);
            } else {
                return CGSizeMake(TTScreenWidth, CGFLOAT_MIN);
            }
        } break;
        default:
            break;
    }
    return CGSizeMake(TTScreenWidth, CGFLOAT_MIN);
}

- (CGSize)layout:(ZZLayout *)layout referenceSizeForFooterInSection:(NSInteger)section {//设置区尾的高度
    return CGSizeMake(TTScreenWidth, CGFLOAT_MIN);
}

- (CGFloat)layout:(ZZLayout*)layout spacingWithLastSectionForSectionAtIndex:(NSInteger)section {//本区区头和上个区区尾的间距
    return 0;
}

- (UIColor *)layout:(UICollectionView *)layout colorForSection:(NSInteger)section {//设置不同分区的不同背景颜色
    return [UIColor whiteColor];
}
#pragma mark - productDetailRichTextCellDelegate
- (void)productDetailRichTextCellBackHeight:(CGFloat)cellHeight
{
    //NSLog(@"cellHeight:%f",cellHeight);
    _productDetailmodel.richTextModel.richTextModulesHeight = cellHeight;
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.collectionView reloadData];
    });
}
#pragma mark Share
- (void)share {

    CommonShareModel *model = [[CommonShareModel alloc] init];
    model.url = [NSString stringWithFormat:@"%@%@?goodsId=%@&myCode=%@",BA_GlobalH5_Domain,@"/marriageProducts",self.goodsId,[TTUserModel sharedObject].myCode];
    model.title = self.productDetailmodel.sellerGoodsModel.goodsName;
    model.content = @"婚前婚后邀您体验";
    model.image = self.productDetailmodel.bannerPics.firstObject;
    [[TT_ShareManager share] callShareViewWithModel:model];
}
#pragma mark SKU Module
- (void)showSKUWithType:(ProductSKUViewActionType)type {
        
    self.skuView.frame = CGRectMake(10, 10, TTScreenWidth,TTScreenHeight * 0.75);
    [self.skuView fillSkuViewWithArray:self.productDetailmodel.sellerGoodsModel.sellerGoodsSpecs Type:type];
    
    self.popView = [LSTPopView initWithCustomView:self.skuView
                                                popStyle:LSTPopStyleSmoothFromBottom
                                            dismissStyle:LSTDismissStyleSmoothToBottom];
    self.popView.hemStyle = LSTHemStyleBottom;

    WEAKSELF
    self.popView.popDuration = 0.5;
    self.popView.dismissDuration = 0.5;
    self.popView.isClickFeedback = YES;
    self.popView.bgClickBlock = ^{

        [weakSelf.popView dismiss];
    };

    [self.popView pop];
}

- (void)showNotice {
        
    self.noticeView.frame = CGRectMake(10, 10, TTScreenWidth,300);
    self.popView = [LSTPopView initWithCustomView:self.noticeView
                                                popStyle:LSTPopStyleSmoothFromBottom
                                            dismissStyle:LSTDismissStyleSmoothToBottom];
    self.popView.hemStyle = LSTHemStyleBottom;

    WEAKSELF
    self.popView.popDuration = 0.5;
    self.popView.dismissDuration = 0.5;
    self.popView.isClickFeedback = YES;
    self.popView.bgClickBlock = ^{

        [weakSelf.popView dismiss];
    };

    [self.popView pop];
}

#pragma mark- 懒加载
- (UICollectionView *)collectionView {
    if (!_collectionView) {
        
        ZZLayout *layout = [[ZZLayout alloc] initWith:ZZLayoutFlowTypeVertical delegate:self];
        //打开区头悬浮功能(默认关闭)
        layout.sectionHeadersPinToVisibleBounds = NO;
        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.backgroundColor = UIColorHex(0xf1f1f1);
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        
        [_collectionView registerNib:[UINib nibWithNibName:@"MarriageProductCell" bundle:nil] forCellWithReuseIdentifier:@"MarriageProductCellID"];

        [_collectionView registerClass:[ProductDetailRichTextCell class] forCellWithReuseIdentifier:@"ProductDetailRichTextCellID"];

        
        [_collectionView registerNib:[UINib nibWithNibName:@"ProductDetailInfoCell" bundle:nil] forCellWithReuseIdentifier:@"ProductDetailInfoCellID"];

        [_collectionView registerNib:[UINib nibWithNibName:@"ProductDetailCouponCell" bundle:nil] forCellWithReuseIdentifier:@"ProductDetailCouponCellID"];
                
        [_collectionView registerNib:[UINib nibWithNibName:@"ProductDetailNormalShowCell" bundle:nil] forCellWithReuseIdentifier:@"ProductDetailNormalShowCellID"];
                
        [_collectionView registerNib:[UINib nibWithNibName:@"ProductDetailEvaluationCell" bundle:nil] forCellWithReuseIdentifier:@"ProductDetailEvaluationCellID"];

        
        [_collectionView registerNib:[UINib nibWithNibName:@"ProductDetailNormalSectionView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailNormalSectionView"];
        
        [_collectionView registerNib:[UINib nibWithNibName:@"ProductDetailEvaluationHeader" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailEvaluationHeader"];
        
        
        [_collectionView registerNib:[UINib nibWithNibName:@"ProductDetailSectionFooterView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ProductDetailSectionFooterView"];

        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.showsVerticalScrollIndicator = NO;

        _collectionView.bounces = YES;
        self.edgesForExtendedLayout = UIRectEdgeNone;
        if (@available(iOS 11.0, *)) {
            _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        
    }
    return _collectionView;
}

- (ProductDetailNaviView *)naviView {
    
    if (!_naviView) {
        _naviView = [[NSBundle mainBundle] loadNibNamed:@"ProductDetailNaviView"owner:nil options:nil].firstObject;
    }
    return _naviView;
}

- (ProductDetailBottomView *)bottomView {
    
    if (!_bottomView) {
        _bottomView = [[NSBundle mainBundle] loadNibNamed:@"ProductDetailBottomView"owner:nil options:nil].firstObject;
    }
    return _bottomView;
}

- (ProductSKUView *)skuView {
    if (!_skuView) {
        _skuView = [[NSBundle mainBundle] loadNibNamed:@"ProductSKUView"owner:nil options:nil].firstObject;
    }
    return _skuView;
}

- (StoreDetailNoticeView *)noticeView {
    if (!_noticeView) {
        _noticeView = [[NSBundle mainBundle] loadNibNamed:@"StoreDetailNoticeView"owner:nil options:nil].firstObject;
        WEAKSELF
        _noticeView.StoreDetailNoticeViewBlock = ^{
            [weakSelf.popView dismiss];
        };
    }
    return _noticeView;
}

- (ProductDetailModel *)productDetailmodel {
    if (!_productDetailmodel) {
        _productDetailmodel = [[ProductDetailModel alloc] init];
    }
    return _productDetailmodel;
}

- (CommonShopCartModel *)handleModel {
    if (!_handleModel) {
        _handleModel = [[CommonShopCartModel alloc] init];
    }
    return _handleModel;
}

- (void)request_goodsDetail {
    
    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:self.goodsId forKey:@"goodsId"];
    [dic setValue:[TTUserModel sharedObject].userId forKey:@"userId"];

    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_PackageDetail];
    
    WEAKSELF
    [SVProgressHUD showWithStatus:@"正在加载"];
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        
        [SVProgressHUD dismiss];
        if ([data isKindOfClass:[NSDictionary class]]) {

            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                NSDictionary *resultDic = [data valueForKey:@"data"];
                if (![resultDic isKindOfClass:[NSDictionary class]]) {
                    return;
                }
                NSArray *sysCouponList = [resultDic valueForKey:@"sysCouponList"];
                NSArray *userEvaluateList = [resultDic valueForKey:@"userEvaluateList"];
                NSArray *sellerGoodsList = [resultDic valueForKey:@"sellerGoodsList"];
                NSArray *SellerPromiseLabelAuthernticationList = [resultDic valueForKey:@"SellerPromiseLabelAuthernticationList"];

                NSArray *videoList = [resultDic valueForKey:@"videoList"];
                NSArray *lunboList = [resultDic valueForKey:@"lunboList"];
                NSArray *imgTextList = [resultDic valueForKey:@"imgTextList"];

                NSDictionary *seller = [resultDic valueForKey:@"seller"];
                NSDictionary *sellerGoods = [resultDic valueForKey:@"sellerGoods"];
                NSDictionary *sellerExpress = [resultDic valueForKey:@"sellerExpress"];

                NSDictionary *userCollection = [resultDic valueForKey:@"userCollection"];
                weakSelf.productDetailmodel.userCollection = [CommonFavorModel modelWithDictionary:userCollection];
                if (weakSelf.productDetailmodel.userCollection.isDel == 2) {
                    weakSelf.productDetailmodel.isCollect = YES;
                } else {
                    weakSelf.productDetailmodel.isCollect = NO;
                }
                
                weakSelf.productDetailmodel.sellerModel = [CommonSellerModule modelWithDictionary:seller];
                
                if ([sellerExpress isKindOfClass:[NSDictionary class]]) {
                    weakSelf.productDetailmodel.sellerExpress = [CommonExpressModel modelWithDictionary:sellerExpress];
                }
                
                weakSelf.productDetailmodel.sellerGoodsModel = [CommonPackageModel modelWithJSON:sellerGoods];
                
                if (weakSelf.productDetailmodel.sellerGoodsModel.goodsStatus == 2) {
                    [TT_Alert alert:@"该婚品已下架" doneAction:^{
                        [weakSelf.navigationController popViewControllerAnimated:YES];
                    }];
                    return;
                }
                                
                NSArray *sellerGoodsSpecs = [sellerGoods valueForKey:@"sellerGoodsSpecs"];
                if ([sellerGoodsSpecs isKindOfClass:[NSArray class]]) {
                    weakSelf.productDetailmodel.sellerGoodsModel.sellerGoodsSpecs = @[].mutableCopy;
                    for (int i = 0; i < sellerGoodsSpecs.count; i++) {
                        NSDictionary *sellerGoodsSpecsDic = sellerGoodsSpecs[i];
                        CommonSkuModel *model = [CommonSkuModel modelWithDictionary:sellerGoodsSpecsDic];
                        if (i==0) {
                            model.isSelect = YES;
                        }
                        [weakSelf.productDetailmodel.sellerGoodsModel.sellerGoodsSpecs addObject:model];
                    }
                }

                weakSelf.productDetailmodel.couponArray = @[].mutableCopy;
                if ([sysCouponList isKindOfClass:[NSArray class]]) {
                    for (int i=0; i < sysCouponList.count; i++) {
                        NSDictionary *sysCouponListDic = sysCouponList[i];
                        CommonCouponModel *couponModel = [CommonCouponModel modelWithDictionary:sysCouponListDic];
                        [weakSelf.productDetailmodel.couponArray addObject:couponModel];
                    }
                }

                weakSelf.productDetailmodel.evaluateArray = @[].mutableCopy;
                if ([userEvaluateList isKindOfClass:[NSArray class]]) {
                    for (int i=0; i < userEvaluateList.count; i++) {
                        NSDictionary *userEvaluateListDic = userEvaluateList[i];
                        CommonEvaluateModel *evaluateModel = [CommonEvaluateModel modelWithDictionary:userEvaluateListDic];
                        
                        NSArray *imageUrls = [userEvaluateListDic valueForKey:@"imageUrls"];
                        if ([imageUrls isKindOfClass:[NSArray class]]) {
                            evaluateModel.imageUrls = @[].mutableCopy;
                            for (int j = 0; j < imageUrls.count; j++) {
                                CommonImageModel *imgModel = [CommonImageModel modelWithDictionary:imageUrls[j]];
                                [evaluateModel.imageUrls addObject:imgModel];
                            }
                        }
                        
                        evaluateModel.infoHeight = 60.0f;
                        evaluateModel.evaluateTextHeight = [Utilities getStringHeightWithText:evaluateModel.ueEvaluateContent font:[UIFont systemFontOfSize:12] viewWidth:TTScreenWidth-30];
                        NSInteger lineCount = evaluateModel.imageUrls.count/3;
                        if (evaluateModel.imageUrls.count%3>0) {
                            lineCount++;
                        }
                        evaluateModel.collectionViewHeight = lineCount * ((TTScreenWidth - 30)/3);
                        evaluateModel.thumbHeight = 40.0f;
                        evaluateModel.itemHeight = evaluateModel.infoHeight + evaluateModel.evaluateTextHeight + evaluateModel.collectionViewHeight + evaluateModel.thumbHeight;
                        
                        [weakSelf.productDetailmodel.evaluateArray addObject:evaluateModel];
                    }
                }

                weakSelf.productDetailmodel.sellerGoodsList = @[].mutableCopy;
                if ([sellerGoodsList isKindOfClass:[NSArray class]]) {
                    for (int i = 0; i < sellerGoodsList.count; i++) {
                        NSDictionary *sellerGoodsListDic = sellerGoodsList[i];
                        CommonPackageModel *packageModel = [CommonPackageModel modelWithJSON:sellerGoodsListDic];
                        [weakSelf.productDetailmodel.sellerGoodsList addObject:packageModel];
                    }
                }
                
                self.productDetailmodel.videoList = @[].mutableCopy;
                if ([videoList isKindOfClass:[NSArray class]]) {
                    for (int i = 0; i < videoList.count; i++) {
                        NSDictionary *videoListDic = videoList[i];
                        CommonMediaModel *model = [CommonMediaModel modelWithDictionary:videoListDic];
                        if (model.url.length > 0) {
                            weakSelf.productDetailmodel.videoUrl = model.url;
                        }
                        [weakSelf.productDetailmodel.videoList addObject:model];
                    }
                }
                
                weakSelf.productDetailmodel.lunboList = @[].mutableCopy;
                weakSelf.productDetailmodel.bannerPics = @[].mutableCopy;
                if ([lunboList isKindOfClass:[NSArray class]]) {
                    for (int i = 0; i < lunboList.count; i++) {
                        NSDictionary *lunboListDic = lunboList[i];
                        CommonMediaModel *model = [CommonMediaModel modelWithDictionary:lunboListDic];
                        
                        if (model.url.length > 0) {
                            [weakSelf.productDetailmodel.bannerPics addObject:model.url];
                        }
                        [weakSelf.productDetailmodel.lunboList addObject:model];
                    }
                }
                
                weakSelf.productDetailmodel.imgTextList = @[].mutableCopy;
                weakSelf.productDetailmodel.images = @[].mutableCopy;
                if ([imgTextList isKindOfClass:[NSArray class]]) {
                    for (int i = 0; i < imgTextList.count; i++) {
                        NSDictionary *imgTextListDic = imgTextList[i];
                        CommonMediaModel *model = [CommonMediaModel modelWithDictionary:imgTextListDic];
                        if (model.url.length > 0) {
                            [weakSelf.productDetailmodel.images addObject:model.url];
                        }
                        [weakSelf.productDetailmodel.imgTextList addObject:model];
                    }
                }
                
                if ([SellerPromiseLabelAuthernticationList isKindOfClass:[NSArray class]]) {
                    weakSelf.productDetailmodel.SellerPromiseLabelAuthernticationList = @[].mutableCopy;
                    weakSelf.productDetailmodel.promiseArray = @[].mutableCopy;
                    
                    for (int i = 0; i < SellerPromiseLabelAuthernticationList.count; i++) {
                        NSDictionary *SellerPromiseLabelAuthernticationListDic = SellerPromiseLabelAuthernticationList[i];
                        CommonPromiseTagModel *model = [CommonPromiseTagModel modelWithDictionary:SellerPromiseLabelAuthernticationListDic];
                        if (model.promiseLabelName.length > 0) {
                            [weakSelf.productDetailmodel.promiseArray addObject:model.promiseLabelName];
                        }
                        
                        [weakSelf.productDetailmodel.SellerPromiseLabelAuthernticationList addObject:model];
                    }
                }
                
                //填充提交数据
                weakSelf.handleModel.sellerGoodsModel = weakSelf.productDetailmodel.sellerGoodsModel;
                weakSelf.handleModel.sellerModel = weakSelf.productDetailmodel.sellerModel;
                [weakSelf prepareData];
                [weakSelf initView];
                [weakSelf.collectionView reloadData];
            }
        }
        
    } FailedBlock:^(NSError * _Nonnull error) {
        
        [SVProgressHUD dismiss];
    }];
}

- (void)request_AddCart {
    
    NSMutableDictionary *dic = @{}.mutableCopy;
    dic = [self.handleModel.sellerGoodsSpecs modelToJSONObject];
    [dic setValue:[TTUserModel sharedObject].userId forKey:@"userId"];

    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_AddCart];
    
    [SVProgressHUD showWithStatus:@"正在加载"];
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        
        [SVProgressHUD dismiss];
        if ([data isKindOfClass:[NSDictionary class]]) {
            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {

                [SVProgressHUD showSuccessWithStatus:[data valueForKey:@"message"]];
                [SVProgressHUD dismissWithDelay:1];
            } else {
                [SVProgressHUD showErrorWithStatus:[data valueForKey:@"message"]];
                [SVProgressHUD dismissWithDelay:1];
            }
        }
        
    } FailedBlock:^(NSError * _Nonnull error) {
        [SVProgressHUD dismiss];
    }];
}

- (void)refreshNaviStatus {
    if (self.productDetailmodel.isCollect) {
        [self.naviView.favoriteBtn setImage:[UIImage imageNamed:@"store_guanzhu_sel"] forState:UIControlStateNormal];
    } else {
        [self.naviView.favoriteBtn setImage:[UIImage imageNamed:@"store_guanzhu"] forState:UIControlStateNormal];
    }
}

@end
